PostCSS Browser Comments lets you keep only the CSS you need based on
comments and your browserslist.
html {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
The comment and rule above would be removed with the following browserslist:
last 2 chrome versions
The rule below would be more carefully altered:
hr {
box-sizing: content-box;
height: 0;
overflow: visible;
}
hr {
box-sizing: content-box;
height: 0;
}
PostCSS Browser Comments can remove rules based upon the comment above them,
or it can remove declarations using numbered comments that reference the rule
above them. In the later case, when all of the numbered comments are removed,
then the entire rule and comment are also removed.
Usage
Add PostCSS Browser Comments to your project:
npm install postcss-browser-comments --save-dev
Use PostCSS Browser Comments to process your CSS:
const postcssBrowserComments = require('postcss-browser-comments');
postcssBrowserComments.process(YOUR_CSS );
Or use it as a PostCSS plugin:
const postcss = require('postcss');
const postcssBrowserComments = require('postcss-browser-comments');
postcss([
postcssBrowserComments()
]).process(YOUR_CSS );
PostCSS Browser Comments runs in all Node environments, with special instructions for:
Options
browsers
The browsers
option overrides of the project’s browserslist.
postcssBrowserComments({
browsers: 'last 2 versions'
});